package com.numberone.web.controller.typeList;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.numberone.common.annotation.Log;
import com.numberone.common.enums.BusinessType;
import com.numberone.system.domain.TypeFirstInfo;
import com.numberone.system.service.ITypeFirstInfoService;
import com.numberone.framework.web.base.BaseController;
import com.numberone.common.page.TableDataInfo;
import com.numberone.common.base.AjaxResult;
import com.numberone.common.utils.poi.ExcelUtil;

/**
 * 一级分类 信息操作处理
 * 
 * @author numberone
 * @date 2020-09-27
 */
@Controller
@RequestMapping("/system/typeFirstInfo")
public class TypeFirstInfoController extends BaseController
{
    private String prefix = "system/typeFirstInfo";
	
	@Autowired
	private ITypeFirstInfoService typeFirstInfoService;
	
	@RequiresPermissions("system:typeFirstInfo:view")
	@GetMapping()
	public String typeFirstInfo()
	{
	    return prefix + "/typeFirstInfo";
	}
	
	/**
	 * 查询一级分类列表
	 */
	@RequiresPermissions("system:typeFirstInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TypeFirstInfo typeFirstInfo)
	{
		startPage();
        List<TypeFirstInfo> list = typeFirstInfoService.selectTypeFirstInfoList(typeFirstInfo);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出一级分类列表
	 */
	@RequiresPermissions("system:typeFirstInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TypeFirstInfo typeFirstInfo)
    {
    	List<TypeFirstInfo> list = typeFirstInfoService.selectTypeFirstInfoList(typeFirstInfo);
        ExcelUtil<TypeFirstInfo> util = new ExcelUtil<TypeFirstInfo>(TypeFirstInfo.class);
        return util.exportExcel(list, "typeFirstInfo");
    }
	
	/**
	 * 新增一级分类
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存一级分类
	 */
	@RequiresPermissions("system:typeFirstInfo:add")
	@Log(title = "一级分类", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TypeFirstInfo typeFirstInfo)
	{		
		return toAjax(typeFirstInfoService.insertTypeFirstInfo(typeFirstInfo));
	}

	/**
	 * 修改一级分类
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		TypeFirstInfo typeFirstInfo = typeFirstInfoService.selectTypeFirstInfoById(id);
		mmap.put("typeFirstInfo", typeFirstInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存一级分类
	 */
	@RequiresPermissions("system:typeFirstInfo:edit")
	@Log(title = "一级分类", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TypeFirstInfo typeFirstInfo)
	{		
		return toAjax(typeFirstInfoService.updateTypeFirstInfo(typeFirstInfo));
	}
	
	/**
	 * 删除一级分类
	 */
	@RequiresPermissions("system:typeFirstInfo:remove")
	@Log(title = "一级分类", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(typeFirstInfoService.deleteTypeFirstInfoByIds(ids));
	}
	
}
